package org.apache.james.mime4j.field;

import java.util.HashMap;
import java.util.Map;

public class DelegatingFieldParser
  implements FieldParser
{
  private FieldParser defaultParser;
  private Map parsers = new HashMap();

  public DelegatingFieldParser()
  {
    this.defaultParser = new UnstructuredField.Parser();
  }

  public FieldParser getParser(String paramString)
  {
    FieldParser localFieldParser2;
    FieldParser localFieldParser1 = (FieldParser)this.parsers.get(paramString.toLowerCase());
    if (localFieldParser1 == null)
      localFieldParser2 = this.defaultParser;
    while (true)
    {
      return localFieldParser2;
      localFieldParser2 = localFieldParser1;
    }
  }

  public Field parse(String paramString1, String paramString2, String paramString3)
  {
    return getParser(paramString1).parse(paramString1, paramString2, paramString3);
  }

  public void setFieldParser(String paramString, FieldParser paramFieldParser)
  {
    this.parsers.put(paramString.toLowerCase(), paramFieldParser);
  }
}